package com.chaoyong.higo.fragment;

import java.util.List;
import java.util.Map;

import com.chaoyong.higo.R;
import com.chaoyong.higo.adapter.FragAllGoodsAdapter;
import com.chaoyong.higo.base.BaseFragment;
import com.chaoyong.higo.bean.GetAllGoodsBean_z;
import com.chaoyong.higo.bean.ListEntity;
import com.chaoyong.higo.bean.WiningGoodsBean;
import com.chaoyong.higo.utils.V;
import com.chaoyong.higo.view.BadgeView;
import com.chaoyong.higo.view.SelectListView;
import com.chaoyong.higo.view.TitleView;
import com.chaoyong.higo.view.XListView;
import com.chaoyong.higo.view.XListView.IXListViewListener;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 
 * @author Administrator
 * 
 *         {"path":"Home/Goods/index","order":"goods_price desc,5,33,,5"}
 *         接口传的参数的含义：默认5条数据，分类的id，（第一次加载传0，第二次+5，以后每次都加5），加载5条数据。
 *
 *         {"path":"Home/Goods/index","order":"goods_price desc,5,33,,5"}
 *
 */
public class FragNewest extends BaseFragment implements IXListViewListener, OnItemClickListener {

	private TextView title_center_text;

	private Activity activity;
	private XListView mListview;
	private FragAllGoodsAdapter mAdapter;
	private List<WiningGoodsBean.DataEntity.ListEntity> datas;

	private LinearLayout layout;
	private BadgeView badgeView;
	private GetAllGoodsBean_z bean;

	private static ImageView piao;
	private static int width;
	private static int height;

	// 分类的id
	private String class_id = "0";
	private int class_load = 5;

	private List<String> keys;

	private List<ListEntity> entities;

	private ImageView search;

	private int load_type = 0;

	// 点击的是“降序排序”还是“生序排序”，降序排序为0，升序为1
	private int idDesc = 0;

	public FragNewest(BadgeView badgeView2) {
		// TODO Auto-generated constructor stub
		this.badgeView = badgeView2;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		mView = inflater.inflate(R.layout.frag_all_goods_z, container, false);
		return mView;
	}

	private void initTitleView() {
		title_center_text = (TextView) mView.findViewById(R.id.title_center_text);
		title_center_text.setText("最新揭晓");


	}

	@Override
	public void findView() {
		activity = getActivity();
		initTitleView();

		layout = V.f(getActivity(), R.id.main_cart_lay);

		mListview = V.f(mView, R.id.zuiznjiexiao_xlv);
		mAdapter = new FragAllGoodsAdapter(activity);
		mListview.setAdapter(mAdapter);

		mListview.setPullLoadEnable(true);
		mListview.setPullRefreshEnable(true);
		// mListview.setVerticalFadingEdgeEnabled(true);
		mListview.setOnItemClickListener(this);
		mListview.setXListViewListener(this);

	}

	@Override
	public void init() {

	}

	@Override
	public void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		if (datas != null) {
			datas.clear();
		}
		if (datas == null) {

		} else {

		}
	}

	@Override
	public void onCreate(@Nullable Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
	}
	
	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onRefresh() {
		// TODO Auto-generated method stub
		mListview.stopRefresh();
		Toast.makeText(activity, "已经刷新", 0).show();
	}

	@Override
	public void onLoadMore() {
		// TODO Auto-generated method stub
		onLoadMore();
		mListview.stopLoadMore();
	}
}
